home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / Make / reader.c < prev    next >
C/C++ Source or Header  |  1990-04-19  |  2KB  |  121 lines

  1. /*
  2.  *    Read in makefile
  3.  */
  4.  
  5.  
  6. #include <stdio.h>
  7. #include    <ctype.h>
  8. #include "h.h"
  9.  
  10.  
  11. int             lineno;
  12.  
  13.  
  14. /*
  15.  *    Syntax error handler.  Print message, with line number, and exits.
  16.  */
  17. void
  18. error(msg, a1, a2, a3)
  19.     char           *msg;
  20. {
  21.     fprintf(stderr, "%s: ", myname);
  22.     fprintf(stderr, msg, a1, a2, a3);
  23.     if (lineno)
  24.     fprintf(stderr, " near line %d", lineno);
  25.     fputc('\n', stderr);
  26.     exit(1);
  27. }
  28.  
  29.  
  30. /*
  31.  *    Read a line into the supplied string of length LZ.  Remove
  32.  *    comments, ignore blank lines. Deal with    quoted (\) #, and
  33.  *    quoted newlines.  If EOF return TRUE.
  34.  */
  35. bool
  36. getline(str, fd)
  37.     char           *str;
  38.     FILE           *fd;
  39. {
  40.     register char  *p;
  41.     char           *q;
  42.     char           *point;
  43.     int             pos = 0;
  44.  
  45.  
  46.     for (;;) {
  47.  
  48.     point = str + pos;
  49.  
  50.     if (fgets( point, LZ - 1 - pos, fd) == (char *) 0)
  51.         return TRUE;    /* EOF */
  52.  
  53.     lineno++;
  54.  
  55.     if ((p = index( point, '\n')) == (char *) 0) {
  56.  
  57.             if (feof(fd)) {        /* Fake a final newline if missing */
  58.                 strcat( point, "\n");
  59.                 p = index( point, '\n');
  60.             }
  61.         else
  62.                 error("Line too long");
  63.         }
  64.  
  65.     if (p[-1] == '\\') {    /* This won't work if there are trailing chars */
  66.         p[-1] = '\n';
  67.         pos = p - str;
  68.         continue;
  69.     }
  70.     p = str;
  71.     while (((q = index(p, '#')) != (char *) 0) &&
  72.            (p != q) && (q[-1] == '\\')) {
  73.         char           *a;
  74.  
  75.         a = q - 1;        /* Del \ chr; move rest back  */
  76.         p = q;
  77.         while (*a++ = *q++);
  78.     }
  79.     if (q != (char *) 0) {
  80.         q[0] = '\n';
  81.         q[1] = '\0';
  82.     }
  83.     p = str;
  84.     while (isspace(*p))    /* Checking for blank  */
  85.         p++;
  86.  
  87.     if (*p != '\0')
  88.         return FALSE;
  89.     pos = 0;
  90.     }
  91. }
  92.  
  93.  
  94. /*
  95.  *    Get a word from the current line, surounded by white space.
  96.  *    return a pointer to it. String returned has no white spaces
  97.  *    in it.
  98.  */
  99. char           *
  100. gettok(ptr)
  101.     char          **ptr;
  102. {
  103.     register char  *p;
  104.  
  105.  
  106.     while (isspace(**ptr))    /* Skip spaces  */
  107.     (*ptr)++;
  108.  
  109.     if (**ptr == '\0')        /* Nothing after spaces  */
  110.     return NULL;
  111.  
  112.     p = *ptr;            /* word starts here  */
  113.  
  114.     while ((**ptr != '\0') && (!isspace(**ptr)))
  115.     (*ptr)++;        /* Find end of word  */
  116.  
  117.     *(*ptr)++ = '\0';        /* Terminate it  */
  118.  
  119.     return (p);
  120. }
  121.